package com.zjcode.cdcer.controller;

import com.chinatechstar.component.commons.controller.BaseController;
import com.chinatechstar.component.commons.result.ListResult;
import com.chinatechstar.component.commons.result.ResultBuilder;
import com.chinatechstar.component.commons.supports.PageData;
import com.chinatechstar.component.commons.utils.ExcelUtils;
import com.zjcode.cdcer.model.basic.JsonObj;
import com.zjcode.cdcer.service.CerSysteminitImportInfoService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.map.HashedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@RestController
@Slf4j
@RequestMapping("/v1/cerSysteminitImportInfo/")
public class CerSysteminitImportInfoController extends BaseController {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private CerSysteminitImportInfoService cerSysteminitImportInfoService;

    @PostMapping("listAllTableData")
    @ApiOperation("获取所有的初始数据信息列表")
    public ListResult<Object> listAllTableData(@RequestBody PageData pageData) {
        return ResultBuilder.buildListSuccess(cerSysteminitImportInfoService.listAllTableData(
                pageData));
    }

    @PostMapping("batchDeletion")
    @ApiOperation("批量删除")
    public JsonObj batchDeletion(@RequestBody PageData pageData) {
        return cerSysteminitImportInfoService.batchDeletion(pageData);
    }

    @PostMapping("oneClickDelete")
    @ApiOperation("一键删除")
    public JsonObj oneClickDelete(@RequestBody PageData pageData) {
        return cerSysteminitImportInfoService.oneClickDelete(pageData);
    }

    @PostMapping("queryAllExportData")
    @ApiOperation("查询待导出的所有数据")
    public JsonObj queryAllExportData(@RequestBody PageData pageData) {
        List<LinkedHashMap<String, Object>> list = cerSysteminitImportInfoService.queryAllExportDataBy(
                pageData);
        Map<String, Object> map = new HashedMap<>();
        map.put("data", list);
        return JsonObj.success(map);
    }


    @PostMapping("exportInitForGJMode")
    @ApiOperation("导出初始数据(国家系统导出模板)")
    public void exportInitForGJMode(HttpServletResponse response) {
        PageData pageData = getPageData();
        cerSysteminitImportInfoService.exportInitForGJMode(pageData,response);
    }
}
